package com.shenmazong.ware.recv;

import com.rabbitmq.client.Channel;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.stereotype.Component;

import java.io.IOException;

/**
 * @author 军哥
 * @version 1.0
 * @description: TODO
 * @date 2022/6/30 16:13
 */

@Component
@Slf4j
public class RecvMessage {

    @RabbitListener(queues = "workQueue")
    public void onWorkMessage(Message message, Channel channel) {
        try {
            //--1
            byte[] body = message.getBody();
            String msg = new String(body);

            //--2
            channel.basicAck(message.getMessageProperties().getDeliveryTag(), true);

            log.info("onWorkMessage:"+msg);
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

}
